<template>
	<button class="uni-primary" @click="payAction">支付</button>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onload(res) {
			
		},
		mounted() {
			
		},
		methods: {
			payAction() {
				var orderInfo = '';  //从服务器获取的订单
				uni.getProvider({
				    service: 'payment',
				    success: function (res) {
				        console.log(res.provider)
				        if (~res.provider.indexOf('alipay')) {
				            uni.requestPayment({
				                "provider": "alipay",   //固定值为"alipay"
				                "orderInfo": orderInfo, //此处为服务器返回的订单信息字符串
				                success: function (res) {
				                    var rawdata = JSON.parse(res.rawdata);
				                    console.log("支付成功");
				                },
				                fail: function (err) {
				                    console.log('支付失败:' + JSON.stringify(err));
				                }
				            });
				        }
				    }
				});
			}
		}
	}
</script>
<style>
</style>